/* CombiStatusCheck.js <?php
#   --------------------------------------------------------------
#   CombiStatusCheck.js 2011-01-24 gambio
#   Gambio GmbH
#   http://www.gambio.de
#   Copyright (c) 2011 Gambio GmbH
#   Released under the GNU General Public License (Version 2)
#   [http://www.gnu.org/licenses/gpl-2.0.html]
#   --------------------------------------------------------------
?>*/
/*<?php
if($GLOBALS['coo_debugger']->is_enabled('uncompressed_js') == false)
{
?>*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9 7(){$(X).s(9(){2(4)5.6(\'7 s\')});j.m=p;j.n=9(b,c){2(4)5.6(\'7 n \'+b);3 d=j;3 e=b.L(/x/);2(e==-1){2(4)5.6(\'r -1\');K p}2(4)5.6(\'r J\');3 f=b.I(\'x\');3 g=f[1];3 h=[];h.8(\'t=S\');h.8(\'H=\'+k(g));h.8(\'q=\'+k(c));$.y({z:\'A.B\',C:h.D(\'&\'),E:\'F\',v:p,u:9(a){2(4)5.6(\'7 n: \'+a[\'w\']+\' \'+a[\'o\']);d.m=a}})};j.l=9(b,c,d){2(4)5.6(\'7 l\');3 e=j;3 f=[];f.8(\'t=M\');f.8(\'N=\'+k(b));f.8(\'q=\'+k(d));2(O c!=\'P\'){2(4)5.6(\'Q 7 l: R G T U!\')}V{W(3 i=0;i<c.Y;i++){f.8(\'Z[]=\'+k(c[i]))}}$.y({z:\'A.B\',C:f.D(\'&\'),E:\'F\',v:10,u:9(a){$(\'#11\').12(a[\'o\']);2(4)5.6(\'7 l: \'+a[\'w\']+\' \'+a[\'o\']);e.m=a}})}}',62,65,'||if|var|fb|console|log|CombiStatusCheck|push|function||||||||||this|escape|get_combi_status|last_result_json|get_combi_status_by_ext_products_id|STATUS_TEXT|false|need_qty|t_sep_found|ready|module|success|async|STATUS_CODE||ajax|url|request_port|php|data|join|dataType|json|not|combis_id|split|TRUE|return|search|properties_combis_status|products_id|typeof|object|ERROR|p_properties_values_id_array|properties_combis_status_by_combis_id|an|Array|else|for|document|length|properties_values_ids|true|properties_info_text|html'.split('|'),0,{}));
/*<?php
}
else
{
?>*/
function CombiStatusCheck()
{
	$(document).ready(
		function() 
		{
			if(fb)console.log('CombiStatusCheck ready');
		}
	);

	this.last_result_json = false;


	this.get_combi_status_by_ext_products_id = function(p_extended_products_id, p_need_qty)
	{
		if(fb)console.log('CombiStatusCheck get_combi_status_by_ext_products_id '+ p_extended_products_id);

		var coo_this = this;

		var t_sep_found = p_extended_products_id.search(/x/);
		if(t_sep_found == -1)
		{
			if(fb)console.log('t_sep_found -1');
			// no seperator found. unextended products_id
			return false;
		}
		if(fb)console.log('t_sep_found TRUE');

		var t_id_array = p_extended_products_id.split('x');
		var t_combis_id = t_id_array[1];

		var t_transfer_data = [];
		t_transfer_data.push('module=properties_combis_status_by_combis_id');
		t_transfer_data.push('combis_id=' + escape(t_combis_id));
		t_transfer_data.push('need_qty=' + escape(p_need_qty));
		
		$.ajax({
			url: 		'request_port.php',
			data: 		t_transfer_data.join('&'),
			dataType: 	'json',
			async: 		false,
			success: 	function(p_data)
						{
							if(fb)console.log('CombiStatusCheck get_combi_status_by_ext_products_id: ' + p_data['STATUS_CODE'] +' '+ p_data['STATUS_TEXT']);
							coo_this.last_result_json = p_data;
		  				}
		});
	}

	this.get_combi_status = function(p_products_id, p_properties_values_id_array, p_need_qty)
	{
		if(fb)console.log('CombiStatusCheck get_combi_status');
		
		var coo_this = this;
		var send_ajax_request = true;
		
		var t_transfer_data = [];
		t_transfer_data.push('module=properties_combis_status');
		t_transfer_data.push('products_id=' + escape(p_products_id));
		t_transfer_data.push('need_qty=' + escape(p_need_qty));
		
		if(typeof p_properties_values_id_array != 'object')
		{
			if(fb)console.log('ERROR CombiStatusCheck get_combi_status: p_properties_values_id_array not an Array!');
			send_ajax_request = false;
		}
		else
		{
			for(var i=0; i<p_properties_values_id_array.length; i++)
			{
				t_transfer_data.push('properties_values_ids[]=' + escape(p_properties_values_id_array[i]));
			}
		}
		
		if(send_ajax_request == true){
			$.ajax({
				url: 		'request_port.php',
				data: 		t_transfer_data.join('&'),
				dataType: 	'json',
				async: 		true,
				success: 	function(p_data)
							{
								if($('#properties_info_text').length == 1){
									$('#properties_info_text').html(p_data['STATUS_TEXT']);
								}
								if(fb)console.log('CombiStatusCheck get_combi_status: ' + p_data['STATUS_CODE'] +' '+ p_data['STATUS_TEXT']);

								coo_this.last_result_json = p_data;
							}
			});
		}
	}
}
/*<?php
}
?>*/
